﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Avatar.Model;
using AvatarHelper;

public partial class HighLevelJobs : System.Web.UI.Page
{
    int _pageJob;
    int _take = 15;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Page.Title += "高端就业";
            this.Bind(_pageJob);
        }
    }
    protected void btn_UpJob_Click(object sender, EventArgs e)
    {
        _pageJob = Convert.ToInt32(lbl_CurrentJob.Text) - 1;
        if (_pageJob > 0) _pageJob -= 1;
        this.Bind(_pageJob);
    }
    protected void btn_DownJob_Click(object sender, EventArgs e)
    {
        _pageJob = Convert.ToInt32(lbl_CurrentJob.Text) - 1;
        if (_pageJob < Convert.ToInt32(lbl_TotalJob.Text) - 1) _pageJob += 1;
        this.Bind(_pageJob);
    }
    protected void btn_Goto_Click(object sender, EventArgs e)
    {
        try
        {
            if (!string.IsNullOrEmpty(txt_PageJob.Text)) _pageJob = Convert.ToInt32(txt_PageJob.Text) - 1;
        }
        catch { }
        this.Bind(_pageJob);
    }
    protected void Bind(int _pageJob)
    {
        using (var _adc = DBHelper.GetDataContext())
        {
            lbl_CurrentJob.Text = (_pageJob + 1).ToString();
            lbl_TotalJob.Text = (_adc.HighJob.Count() / _take + 1).ToString();
            ListView1.DataSource = _adc.HighJob.OrderByDescending(j => j.PublishDate).Skip(_take * _pageJob).Take(_take);
            ListView1.DataBind();
        }
    }
}
